﻿@page "/DoView"
@using WebsiteForWorkFlow.Data
@inject List<WorkFlowDetail> workFlowDetailViews
@inject List<ParameterEntity> parameterEntityList

<button class="btn btn-primary" @onclick="GetTask">Get Task</button>
<br>
<br>
<div>
@if (workFlowDetailViews != null)
{
    for (var i = 0; i < workFlowDetailViews.Count; i++)
    {
        WorkFlowDetail workFlowDetail = workFlowDetailViews[i];
        <div>
        @workFlowDetail.WorkFlowName-@workFlowDetail.StepName       &ensp;&ensp;
        <a @onclick="()=>SearchParaters(workFlowDetail.ID)" href="DoView" data-toggle="modal" data-target="#PDialog">PDialog</a>&ensp;
        <a @onclick="()=>Complete(workFlowDetail)" href="">Complete</a>
        </div>
    }
}
</div>
<div class="modal fade" id="PDialog" tabindex="-1" role="dialog" aria-labelledby="ParamertersLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <h4 class="modal-title" id="title">Business Parameters</h4>
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
            </div>
            <div class="model-body">
                <table class="table">
                    <thead>
                        <tr>
                            <th>Sno</th>
                            <th>ID</th>
                            <th>Name</th>
                            <th>Value</th>
                        </tr>
                    </thead>
                    <tbody>
                        @if (parameterEntityList != null)
                            @for (var i = 0; i < parameterEntityList.Count; i++)
                            {
                                ParameterEntity parameterEntity = parameterEntityList[i];
                                <tr>
                                    <td>@(i+1)</td>
                                    <td>@parameterEntity.ID</td>
                                    <td>@parameterEntity.Name</td>
                                    <td>@parameterEntity.Value</td>
                                </tr>
                            }
                    </tbody>
                </table>
            </div>
            <div class="modal-footer">
                @*                    <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
                    <button type="button" class="btn btn-primary">Save</button>*@
            </div>
        </div>

    </div>
</div>

@code {
    private void GetTask()
    {
        workFlowDetailViews = WorkFlowTool.GetAllViews();
        InvokeAsync(() => StateHasChanged());
    }
    private void SearchParaters(string detailID)
    {
        parameterEntityList = WorkFlowTool.GetParameterByDetailID(detailID);
        InvokeAsync(() => StateHasChanged());
    }

    private void Complete(WorkFlowDetail workFlowDetail)
    {
        // Get ViewConfig
        WorkFlowFile workFlowFile = WorkFlowTool.GetViewConfig(workFlowDetail.ID);
        // Notify the workFlow
        Dictionary<string, string> sendData = new Dictionary<string, string>();
        sendData["WorkFlowDetailID"] = workFlowDetail.ID;
        if (workFlowFile.Config.TypeValue == "Form1"
        || workFlowFile.Config.TypeValue == "Form2")
        {
            sendData.Add("WorkFlowTaskResult", DataInstance.Result);
        }
        WorkFlowTool.TaskIsCompleted(sendData);
    }

}
